package com.yiqi.lottery.feature.lottery.view;

import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.suozhang.framework.framework.AM;
import com.suozhang.framework.framework.BaseActivity;
import com.suozhang.framework.utils.T;
import com.yiqi.lottery.R;
import com.yiqi.lottery.common.widget.banner.BannerView;
import com.yiqi.lottery.common.widget.banner.holder.HolderCreator;
import com.yiqi.lottery.common.widget.banner.holder.ViewHolder;
import com.yiqi.lottery.feature.documentary.view.HallFragment;
import com.yiqi.lottery.feature.lottery.view.adapter.MyFragmentAdapter;
import com.yiqi.lottery.framework.DataServer;

import java.util.ArrayList;
import java.util.List;

public class WinningColumnActivity extends BaseActivity {

    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.banner)
    BannerView mBannerView;
    @BindView(R.id.tvtablayout)
    TabLayout mTabLayout;
    @BindView(R.id.tvviewpager)
    ViewPager mViewPager;
    private List<Fragment> list;
    private MyFragmentAdapter adapter;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_winning_column;
    }

    @Override
    protected void initInjector() {

    }


    @Override
    protected void initView() {
        initToolBar(mToolbar, "中奖专栏", true, true);


    }

    @Override
    protected void initData() {
        setBannerData();
        initViewPager();
    }

    /**
     * 设置banner数据
     */
    private void setBannerData() {

        mBannerView.setIndicatorRes(R.drawable.dot_unselect_image, R.drawable.dot_select_image);
        mBannerView.setIndicatorVisible(true);

        mBannerView.setPages(DataServer.getBannerData(), new HolderCreator<BannerViewHolder>() {
            @Override
            public BannerViewHolder createViewHolder() {
                return new BannerViewHolder();
            }
        });
        mBannerView.start();

    }



    public static class BannerViewHolder implements ViewHolder<String> {
        private ImageView mImageView;

        @Override
        public View createView(Context context) {
            // 返回页面布局
            View view = LayoutInflater.from(context).inflate(R.layout.banner_item_normal, null);
            mImageView = view.findViewById(R.id.banner_image);
            return view;
        }

        @Override
        public void onBind(Context context, int position, String data) {
            // 数据绑定
            AM.image().bind(data, mImageView);

            mImageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    T.showShort("click!");
                }
            });
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        mBannerView.pause();//暂停轮播
    }

    @Override
    public void onResume() {
        super.onResume();
        mBannerView.start();//开始轮播
    }

    private void initViewPager() {
        list = new ArrayList<>();
        list.add(new WinningColumnFragment());
        list.add(new WinningColumnFragment2());
        //ViewPager的适配器
        adapter = new MyFragmentAdapter(getSupportFragmentManager(), list);
        mViewPager.setAdapter(adapter);
        //绑定
        mTabLayout.setupWithViewPager(mViewPager);

    }


}
